﻿using System;
using System.Security.Cryptography;

namespace DimMock
{
    /// <summary>
    /// Random value generators
    /// </summary>
    public partial class Random
    {
        /// <summary>
        /// Generation class for random value types.
        /// </summary>
        internal static class Generate
        {
            /// <summary>
            /// Generates a purely random number
            /// </summary>
            /// <param name="min">The min.</param>
            /// <param name="max">The max.</param>
            /// <returns></returns>
            public static int Next(int min = 0, int max = int.MaxValue)
            {
                using (var crypto = new RNGCryptoServiceProvider())
                {
                    byte[] randomNumber = new byte[4];
                    crypto.GetBytes(randomNumber);
                    int result = Math.Abs(BitConverter.ToInt32(randomNumber, 0));
                    if ((max - min + 1) + min == 0)
                        return ((result % 1));
                    return ((result % (max - min + 1)) + min);
                }
            }
        }
    }
}
    
